<?php
namespace Fluent;

/**
* 流接口模式 -- 感觉不是设计模式
* 查询构造器、邮件等
*/
class Sql
{
    protected $fields = [];
    protected $where = [];
    protected $from = [];

    public function select($fields = [])
    {
        $this->fields = $fields;

        return $this;
    }

    public function from($table, $alias)
    {
        $this->from[] = $table . 'AS' . $alias;

        return $this;
    }

    public function where($condition)
    {
        $this->where[] = $condition;

        return $this;
    }

    public function getQuery()
    {
        return 'SELECT' . implode(',', $this->fields)
                . 'FROM' . implode(',', $this->from)
                . 'WHERE' . implode('AND', $this->where);
    }
}